namespace NUnitTests{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Reflection;
    using System.Text;
    using System.Threading;
    using Guia.Core;
    using Guia.Elements;
    using NUnit.Framework;

    [TestFixture]
    public abstract class AbstractWindowTest : AbstractTest
    {
#if UseApplication
        protected Application application;
        protected Window window;
#else
         protected WindowControl window;
#endif

        /// <summary>
        /// Use TestInitialize to run code before running each test 
        /// </summary>
        [SetUp]
        public void MyTestInitialize()
        {
#if UseApplication
                application = Application.Start(@"WpfTestApplication.exe " + TestWindowName());
                window = application.GetWindowByName(TestWindowName());
#else
                MethodInfo method = typeof (AbstractWindowTest).GetMethod("CreateTestWindowHelper");
                MethodInfo genericMethod = method.MakeGenericMethod(this.TestWindowType());
                window = (WindowControl) genericMethod.Invoke(null, null);
#endif
        }

        /// <summary>
        /// Use TestCleanup to run code after each test has run
        /// </summary>
        [TearDown]
        public void MyTestCleanup()
        {
#if UseApplication
                application.Stop();
#else
                window.Stop();
#endif          
            window = null;     
        }

        /// <summary>
        /// The type of the window to use.
        /// </summary>
        protected abstract Type TestWindowType();

        /// <summary>
        /// The name of the window to use.
        /// </summary>
        protected abstract string TestWindowName();

        public static WindowControl CreateTestWindowHelper<T>() where T : System.Windows.Window
        {
            return WindowControl.Start<T>();
        }
    }
}
